#include "swiperwidget.h"
#include "ui_swiperwidget.h"
#include <QDebug>
#include <QFileDialog>

SwiperWidget::SwiperWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SwiperWidget)
{
    ui->setupUi(this);
    ui->label->setScaledContents(true); //内容自适应大小
    fileList = QFileDialog::getOpenFileNames(
                this,
                "选择你的图片",
                "./",
                "Images (*.jpg *.png)");
    fileIndex = 0;
    showImg();
}

SwiperWidget::~SwiperWidget()
{
    delete ui;
}

void SwiperWidget::showImg()
{
    fileIndex =(fileIndex+fileList.size())%fileList.size();
    QPixmap pixMap(fileList.at(fileIndex));
    qDebug()<<"showImg:"<<&pixMap;
    ui->label->setPixmap(pixMap);
}

void SwiperWidget::on_pushButton_clicked()
{
    emit swiperWidgetCloseSign();
}

void SwiperWidget::on_frontBtn_clicked()
{
    fileIndex--;
    showImg();
    const QPixmap* pixMap =ui->label->pixmap();
    qDebug()<<"front:"<<pixMap;
}

void SwiperWidget::on_nextBtn_clicked()
{
    fileIndex++;
    showImg();
}
